/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this
work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the
"License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * *
http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is
distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific
language governing permissions and * limitations under the License. */
/* eslint-disable */
<template>
  <m-list-construction title="任务定义">
    <template slot="conditions">
      <el-tabs v-model="activeName">
        <el-tab-pane
          label="全部任务"
          name="all-task"
        ></el-tab-pane>
        <el-tab-pane
          label="实时任务"
          name="timing-task"
        ></el-tab-pane>
      </el-tabs>
      <m-conditions @on-conditions="_onConditions"> </m-conditions>
    </template>
    <template slot="operation">
      <el-button
        type="primary"
        size="small"
        @click="creatNodeTask"
        v-auth="['operation:product:sync']"
      >创建任务</el-button>
      <nodeTask
        ref="cTask"
        v-if="nodeTaskShow"
      />
    </template>
    <template slot="content">
      <!-- 全部任务 -->
      <template v-if="activeName==='all-task'&&(tenementList.length || total > 0
        )">
        <all-list
          @on-update="_onUpdate"
          :tenement-list="tenementList"
          :page-no="searchParams.pageNo"
          :page-size="searchParams.pageSize"
          :searchVal="searchParams.searchVal"
        >
        </all-list>
        <div class="page-box">
          <el-pagination
            background
            @current-change="_page"
            @size-change="_pageSize"
            :page-size="searchParams.pageSize"
            :current-page.sync="searchParams.pageNo"
            :page-sizes="[10, 30, 50]"
            layout="sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </template>
      <!-- 实时任务 -->
      <template v-if="activeName==='timing-task'&&(tenementList.length || total > 0
        )">
        <timing-list
          @on-update="_onUpdate"
          :tenement-list="tenementList"
          :page-no="searchParams.pageNo"
          :page-size="searchParams.pageSize"
          :searchVal="searchParams.searchVal"
        >
        </timing-list>
        <div class="page-box">
          <el-pagination
            background
            @current-change="_page"
            @size-change="_pageSize"
            :page-size="searchParams.pageSize"
            :current-page.sync="searchParams.pageNo"
            :page-sizes="[10, 30, 50]"
            layout="sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </template>
      <!-- 暂无数据 -->
      <template v-if="!tenementList.length && total <= 0">
        <m-no-data></m-no-data>
      </template>
      <m-spin
        :is-spin="isLoading"
        :is-left="isLeft"
      ></m-spin>
    </template>

  </m-list-construction>
</template>
<script>
  import _ from 'lodash'
  import { getProductList } from '@/conf/home/apis'
  import allList from './components/all-list.vue'
  import timingList from './components/timing-list.vue'
  import mNoData from '@/module/components/noData/noData'
  import listUrlParamHandle from '@/module/mixin/listUrlParamHandle'
  import mConditions from './components/search.vue'
  import mListConstruction from '@/module/components/listConstruction/listConstruction'
  import nodeTask from './components/nodeTask.vue'

  export default {
    name: 'resourceList',
    data () {
      return {
        nodeTaskShow: false,
        activeName: 'all-task',
        total: null,
        isLoading: true,
        tenementList: [],
        searchParams: {
          pageSize: 10,
          pageNo: 1,
        },
        isLeft: true,
      }
    },
    mixins: [listUrlParamHandle],
    props: {},
    methods: {
      /**
       * Query
       */
      _onConditions (o) {
        this.searchParams = _.assign(this.searchParams, o)
        this.searchParams.pageNo = 1
        this._getList(false)
      },
      _page (val) {
        this.searchParams.pageNo = val
      },
      _pageSize (val) {
        this.searchParams.pageSize = val
      },
      _onUpdate () {
        this._debounceGET()
      },
      /* 创建任务 */
      creatNodeTask () {
        this.nodeTaskShow = true
        this.$nextTick(() => {
          this.$refs.cTask.show()
        })
      },
      async _getList (flag) {
        // if (sessionStorage.getItem('isLeft') === 0) {
        //   this.isLeft = false
        // } else {
        //   this.isLeft = true
        // }
        this.isLoading = !flag
        try {
          const res = await getProductList(this.searchParams)
          if (res) {
            const { data } = res
            if (this.searchParams.pageNo > 1 && data.totalList.length === 0) {
              this.searchParams.pageNo = this.searchParams.pageNo - 1
            } else {
              this.tenementList = []
              this.tenementList = data.totalList
              this.total = data.total
              this.isLoading = false
            }
          } else {
            this.$message.warning(res.msg || '')
          }
        } catch (error) {
          console.log('error===>', error)
        } finally {
          this.isLoading = false
        }
      }
    },
    watch: {},
    created () { },
    mounted () { },
    // beforeDestroy () {
    //   sessionStorage.setItem('isLeft', 1)
    // },
    components: { allList, timingList, mListConstruction, mConditions, mNoData, nodeTask }
  }
</script>

<style lang="scss" scoped>
::v-deep .el-tabs__item.is-top {
  // transform: translateX(16px) !important;
  padding-left: 15px !important;
}
::v-deep .el-tabs__item {
  font-size: 16px;
  font-family: PingFang SC, PingFang SC-500;
  text-align: CENTER;
  font-weight: 500;
}

::v-deep .el-tabs__item.is-active {
  color: #33317e;
}
</style>
